// cdn预加载的模块
const externals = {
	'vue': 'Vue',
	'vue-router': 'VueRouter',
	'axios': 'axios',
	'js-cookie': 'Cookies',
	'vuex': "Vuex"
}
// cdn预加载的模块的地址
const cdn = {
	js: [
		'https://cdn.bootcdn.net/ajax/libs/vue/2.6.11/vue.min.js',
		'https://cdn.bootcdn.net/ajax/libs/vue-router/3.2.0/vue-router.min.js',
		'https://cdn.bootcdn.net/ajax/libs/axios/0.19.2/axios.min.js',
		'https://cdn.bootcdn.net/ajax/libs/js-cookie/2.2.1/js.cookie.min.js',
		'https://cdn.bootcdn.net/ajax/libs/vuex/3.5.1/vuex.min.js'
	]
}
module.exports = {
	publicPath: './',  			// vue3解决部署到服务器白屏问题  '/'  =>  ''
    outputDir:'dist',			// 打包目录
    devServer: {
		host: "127.0.0.1",      // 开发模式时的ip
		port: 8090,				// 开发模式时的端口
  },
  chainWebpack: config => {
    // npm run prod (发布模式)
    config.when(process.env.NODE_ENV === 'production', config => {
      config
        .entry('app')
        .clear()
        .add('./src/main-prod.js')
      // 通过externals加载外部CDN资源----1
      config.set('externals', externals)
      // 发布模式的isProd为true
      config.plugin('html').tap(args => {
        args[0].cdn = cdn
        return args
      })
    })
    // npm run dev (开发模式)
    config.when(process.env.NODE_ENV === 'development', config => {
      config
        .entry('app')
        .clear()
        .add('./src/main.js')
    })
  }
};
